import request from '../utils/request';
import { stringify } from 'qs';
import { baseServerUrl } from '../utils/Constant';


const paramConvert = (params) => {
  if(params['localCode'] instanceof Array){
    params['localCode'] = params['localCode'][params['localCode'].length-1];
  }
  return params;
}
export async function companyTypeList(params) {
  return request(baseServerUrl + `/user/sys-comp-type/page?${stringify(params)}`,{
    method: 'GET'
  });
}

export async function companyTypeInsert(params) {
  return request(`${baseServerUrl}/user/sys-comp-type`, {
    method: 'POST',
    body: {
      ...params,
    }
  })
}

export async function companyTypeDel(params) {
  return request(`${baseServerUrl}/user/sys-comp-type`, {
    method: 'DELETE',
    body: {
      ...params,
    }
  })
}

export async function companyTypeEdit(params) {
  return request(`${baseServerUrl}/user/sys-comp-type`, {
    method: 'PUT',
    body: {
      ...params,
    }
  })
}

export async function companyList(params) {
  return request(baseServerUrl + `/user/sys-customer-comp/page?${stringify(params)}`,{
    method: 'GET'
  });
}

export async function companyInsert(params) {
  const convertParam = paramConvert(params);
  return request(`${baseServerUrl}/user/sys-customer-comp`, {
    method: 'POST',
    body: {
      ...convertParam,
    }
  })
}

export async function companyDel(params) {
  const convertParam = paramConvert(params);
  return request(`${baseServerUrl}/user/sys-customer-comp`, {
    method: 'DELETE',
    body: {
      ...convertParam,
    }
  })
}

export async function companyEdit(params) {
  const convertParam = paramConvert(params);
  return request(`${baseServerUrl}/user/sys-customer-comp`, {
    method: 'PUT',
    body: {
      ...convertParam,
    }
  })
}

export async function compTypeResTree(params) {
  return request(`${baseServerUrl}/user/sys-comptype-resource/treeData?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function compTypeResSave(params) {
  let body = new FormData();
  Object.keys(params).map(key => {
    body.append(key,params[key]);
  })
  return request(`${baseServerUrl}/user/sys-comptype-resource/save`, {
    method: 'POST',
    body: body
  })
}



